package com.pat.service;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.pat.manager.LocationManager;
import com.pat.om.Location;

@Path("/services")
public class LocationService {

	private LocationManager mgr = new LocationManager();

	@GET
	@Path("location")
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Location> get() {
		return mgr.get();
	}

	@GET
	@Path("location/{cellNo}")
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Location> get(@PathParam("cellNo") int id) {
		return mgr.get(id);
	}

	@POST
	@Path("/location")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response post(Location location) {
		mgr.post(location);
		return Response.status(201).entity(location).build();
	}

	@PUT
	@Path("/location")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response put(Location location) {
		mgr.put(location);
		return Response.status(201).entity(location).build();
	}

	@DELETE
	@Path("/location/{cellNo}")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response delete(@PathParam("cellNo") int id) {
		int result = mgr.delete(id);
		if (result > 0) {
			return Response.status(200).entity(result).build();
		} else {
			return Response.status(304).entity(0).build();
		}
	}

}
